<?php

class Default_SitemapController extends ExtLb_Controller_Action
{
	private $postTbl;
	private $commentTbl;

    public function init(){
        $this->loadCss('default', 'sitemap', FOLDER_ROOT_NAME);

        $this->postTbl	= new Admin_Model_Posts();
        $this->commentTbl = new Admin_Model_Comments();
        
        //RANDOM POST (BAI VIET NOI BAT)
    	$randPost = $this->postTbl->selectPost('bv.trangThai = 1','baiVietId DESC',10)->query()->fetchAll();
    	$this->view->randPosts = $randPost;
    	
    	$this->view->comments = $this->commentTbl->selectComment(NULL,'yKienId DESC',5)->query()->fetchAll();
    }

    public function indexAction()
    {
        $menu2 = new Admin_Model_Menu2();
		$menu1 = new Admin_Model_Menu1s();
		$fc = Zend_Controller_Front::getInstance();
		
		$sitemap = '<ul class="sitemap">';
		
		$mn1s = $menu1->fetchAllMenu1();
		foreach ($mn1s as $mn1) {
			$sitemap .= '<li class="sitemap-item">';
			
			$mn2s = $menu2->fetchAllMenu2("menu1Id =".$mn1['menu1Id']);
			if (!empty($mn2s['tenMenu2'])){
				$sitemap .='<a href="'.$fc->getBaseUrl().'/default/items/?mn='.$mn1['menu1Id'].'">'.$mn1['tenMenu1'].'</a> ';
					$sitemap .='<ul class="sitemap-item-sub">';
					foreach ($mn2s as $mn2) {
						$sitemap .='<li class="sitemap-item-sub-item">
								<a href="'.$fc->getBaseUrl().'/default/vpages/?vp='.$mn2['menu2Id'].'">'.$mn2['tenMenu2'].'</a>						
							</li>';
					}
					$sitemap .='</ul>';
			}else{
				//INSERT MENU ITEM GIOI THIEU
				if ($mn1['menu1Id']==2){
					$sitemap .= '<a href="'.$fc->getBaseUrl().'/default/vpages/?gt=1">'.$mn1['tenMenu1'].'</a> ';
				}else{
					$sitemap .='<a href="'.$fc->getBaseUrl().'/default/items/">'.$mn1['tenMenu1'].'</a> ';
				}
			}
			$sitemap .='</li>';
			
			
		}
			$sitemap .= '<li class="sitemap-item"><a href="'.$fc->getBaseUrl().'/default/register/">Đăng ký</a></li>';
			$sitemap .= '<li class="sitemap-item"><a href="'.$fc->getBaseUrl().'/default/sitemap/">Sơ đồ Web</a></li>';
		$sitemap .='</ul>';
		
		$this->view->sitemap = $sitemap;
    }


}

